home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / cc68k.arc / CMAIN.C < prev    next >
C/C++ Source or Header  |  1989-09-24  |  3KB  |  116 lines

  1. #include        "stdio.h"
  2. #include        "string.h"
  3. #include        "c.h"
  4. #include        "expr.h"
  5. #include        "gen.h"
  6. #include        "cglbdec.h"
  7.  
  8. /*
  9.  *    68000 C compiler
  10.  *
  11.  *    Copyright 1984, 1985, 1986 Matthew Brandt.
  12.  *  all commercial rights reserved.
  13.  *
  14.  *    This compiler is intended as an instructive tool for personal use. Any
  15.  *    use for profit without the written consent of the author is prohibited.
  16.  *
  17.  *    This compiler may be distributed freely for non-commercial use as long
  18.  *    as this notice stays intact. Please forward any enhancements or question
  19. s
  20.  *    to:
  21.  *
  22.  *        Matthew Brandt
  23.  *        Box 920337
  24.  *        Norcross, Ga 30092
  25.  */
  26.  
  27. char            infile[20],
  28.                 listfile[20],
  29.                 outfile[20];
  30. extern TABLE    tagtable;
  31. int        mainflag;
  32. extern int      total_errors;
  33.  
  34.  main(argc,argv)
  35. int     argc;
  36. char    **argv;
  37. {
  38.         while(--argc) {
  39.                 if( **++argv == '-')
  40.                         options();
  41.                 else if( openfiles(*argv)) {
  42.                         lineno = 0;
  43.                         initsym();
  44.                         getch();
  45.                         getsym();
  46.                         compile();
  47.                         summary();
  48.                         release_global();
  49.                         closefiles();
  50.                         }
  51.                 }
  52. }
  53.  
  54. int    options()
  55. {
  56.   return 0;
  57. }
  58.  
  59. int     openfiles(s)
  60. char    *s;
  61. {
  62. /*        int     ofl; */
  63.  
  64.     strcpy(infile,s);
  65.         strcpy(listfile,s);
  66.         strcpy(outfile,s);
  67.         makename(listfile,".lis");
  68.     makename(outfile,".s");
  69.         if( (input = fopen(infile,"r")) == 0) {
  70.                 printf(" cant open %s\n",infile);
  71.                 return 0;
  72.                 }
  73. /*        ofl = creat(outfile,0);
  74.         if( ofl < 0 )
  75.                 {
  76.                 printf(" cant create %s\n",outfile);
  77.                 fclose(input);
  78.                 return 0;
  79.         }
  80. */
  81.     if( (output = fopen(outfile,"w")) == 0) {
  82.                 printf(" cant open %s\n",outfile);
  83.                 fclose(input);
  84.                 return 0;
  85.                 }
  86.         if( (list = fopen(listfile,"w")) == 0) {
  87.                 printf(" cant open %s\n",listfile);
  88.                 fclose(input);
  89.                 fclose(output);
  90.                 return 0;
  91.                 }
  92.         return 1;
  93. }
  94.  
  95.  makename(s,e)
  96. char    *s, *e;
  97. {       while(*s != 0 && *s != '.')
  98.                 ++s;
  99.         while(*s++ = *e++);
  100. }
  101.  
  102.  summary()
  103. {       printf("\n -- %d errors found.",total_errors);
  104.         fprintf(list,"\f\n *** global scope symbol table ***\n\n");
  105.         list_table(&gsyms,0);
  106.         fprintf(list,"\n *** structures and unions ***\n\n");
  107.         list_table(&tagtable,0);
  108. }
  109.  
  110.  closefiles()
  111. {       fclose(input);
  112.         fprintf(output,"\tEND\t");    /* END directive to output file. */
  113.         fclose(output);
  114.         fclose(list);
  115. }
  116.